home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-09-28 | 2.4 KB | 77 lines |
- /*
- * QuickTime for Java SDK Sample Code
-
- Usage subject to restrictions in SDK License Agreement
- * Copyright: © 1996-1999 Apple Computer, Inc.
-
- */
- import quicktime.app.anim.*;
- import quicktime.qd.*;
- import quicktime.*;
- import java.util.*;
- // We use this class to profile just the tickling times (incl. blit) of the compositor
-
- // we could expand this profiling to include the time between each tickle call, the number of tickle calls a second, etc.
- public class ProfileCompositor extends Compositor {
- public ProfileCompositor (QDGraphics gw, QDColor bgColor, int scale, int period) throws QTException {
- super (gw, bgColor, scale, period);
- }
-
-
- int profileCount = 0;
- long startTime, stopTime;
- boolean isProfiling;
- Vector tickleTimes = new Vector();
- long previousTime;
-
- //the tickle method will invoke the idle method to blit
- // as such we can get an idea of the blit time as well
- //by overiding the idle method and profiling it when we
- // are profiling the tickle method
- public boolean tickle (float er, int time) throws QTException {
- //profile the tickle method and print it every 40 times
- isProfiling = profileCount++ % 40 == 0;
- startTime = System.currentTimeMillis();
-
- boolean ret = super.tickle (er, time);
-
- if (isProfiling) {
- stopTime = System.currentTimeMillis();
- System.out.println (",tickle:" + (stopTime - startTime) + " msecs");
- if (tickleTimes.size() != 0) {
- Enumeration iter = tickleTimes.elements();
- Integer min = new Integer (1000);
- Integer max = new Integer (0);
- int total = 0;
-
- while (iter.hasMoreElements()) {
- Integer el = (Integer)iter.nextElement();
- if (el.intValue() > max.intValue())
- max = el;
- if (el.intValue() < min.intValue())
- min = el;
- total += el.intValue();
- }
- System.out.println ("min=" + min.intValue() + ",max=" + max.intValue() + ",AVG=" + (total / tickleTimes.size()) + "," + tickleTimes);
- }
- tickleTimes = new Vector();
- }
- tickleTimes.addElement (new Integer ((int)(startTime - previousTime)));
- previousTime = startTime;
- return ret;
- }
-
- long idleStartTime, idleStopTime;
-
- protected void idle () throws QTException {
- if (isProfiling)
- idleStartTime = System.currentTimeMillis();
-
- super.idle();
-
- if (isProfiling) {
- idleStopTime = System.currentTimeMillis();
- System.out.print ("* * * SpriteWorldIdle:" + (idleStopTime - idleStartTime) + " msecs");
- }
- }
- }